Uec3.ServiceListWindow = Ext.extend(Ext.app.Module, {
			gridStore : null,
			createService : function(rowIndex) {
				var desktop = this.app.getDesktop();
				var detailWindow = new Uec3.ServiceDetailWindow();
				detailWindow.init();
				detailWindow.createWindow(this.app);
			},
			modifyService : function(rowIndex) {
				var record = this.gridStore.getAt(rowIndex);
				var desktop = this.app.getDesktop();
				var detailWindow = new Uec3.ServiceDetailWindow();
				detailWindow.init();
				detailWindow.createWindow(this.app, record);
			},
			createElements : function() {
				var module = this;
				module.gridStore = new Ext.data.Store({
							proxy : new Ext.data.HttpProxy({
										url : Uec3.App.Constants.homeUrl + "/companyPackage/listServices.do"
									}),
							baseParams : {
								start : 0,
								limit : 20
							},
							remoteSort : true,
							reader : new Ext.data.JsonReader({
										totalProperty : 'total',
										root : 'items'
									}, [{
												name : 'id'
											}, {
												name : 'code'
											}, {
												name : 'name'
											}, {
												name : 'target'
											}, {
												name : 'targetName'
											}, {
												name : 'selectable'
											}])
						});
				var gridColumnAction = {
					header : "操作",
					width : 40,
					sortable : false,
					dataIndex : 'id',
					renderer : this.moduleActionRenderer([{
								func : "modifyService",
								desc : "编辑",
								reader : function(value, cellmeta, record, rowIndex, columnIndex, store) {
									return rowIndex;
								}
							}])
				};

				var gridColumnModel = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), gridColumnAction, {
							header : '服务编码',
							width : 150,
							sortable : true,
							dataIndex : 'code'
						}, {
							header : '服务名称',
							width : 370,
							sortable : true,
							dataIndex : 'name'
						}, {
							header : '',
							width : 269,
							hidden : true,
							dataIndex : 'target'
						}, {
							header : '适用目标用户',
							width : 269,
							sortable : true,
							dataIndex : 'targetName'
						}, {
							header : '是否可选',
							width : 150,
							sortable : true,
							dataIndex : 'selectable',
							renderer : Ext.util.Format.booleanRenderer
						}]);
				var gridPanel = new Ext.grid.GridPanel({
							enableColumnMove : false,
							enableColumnMoveResize : false,
							stripeRows : true,
							autoScroll : true,
							width : '100%',
							loadMask : {
								msg : '...加载数据中'
							},
							viewConfig : {
								autoScroll : true,
								columnsText : '显示的列',
								scrollOffset : 20,
								sortAscText : '升序',
								sortDescText : '降序'
							},
							tbar : new Ext.Toolbar(['-', {
										text : '新增服务',
										handler : function() {
											module.createService();
										}
									}]),
							bbar : new Ext.PagingToolbar({
										pageSize : 20,
										store : module.gridStore,
										displayInfo : true,
										displayMsg : '第 {0} - {1} 条  共 {2} 条',
										emptyMsg : '没有记录'
									}),
							iconCls : 'acc-icon',
							cm : gridColumnModel,
							store : module.gridStore
						});
				module.gridStore.load();
				return gridPanel;
			},

			init : function(initParams) {
			},

			createWindow : function() {

				var desktop = this.app.getDesktop();
				var win = desktop.getWindow('serviceListWin');
				if (!win) {
					win = desktop.createWindow({
								title : '服务类型列表',
								id : 'serviceListWin',
								iconCls : 'acc-icon',
								taskbuttonTooltip : '服务类型列表',
								width : 980,
								height : 560,
								autoScroll : true,
								shim : false,
								animCollapse : false,
								constrainHeader : true,
								maximizable : false,
								resizable : false,
								layout : "fit",
								items : this.createElements()
							});
				}
				win.show();
			}
		});

Uec3.ServiceDetailWindow = Ext.extend(Ext.app.Module, {
			detailFormAjax : null,
			serviceTargetStore : new Ext.data.Store({
						proxy : new Ext.data.HttpProxy({
									url : Uec3.App.Constants.homeUrl + '/dictionary/findByVarGroup.do?group=service_target'
								}),
						reader : new Ext.data.JsonReader({
									root : '',
									fields : [{
												name : 'varIndex'
											}, {
												name : 'varName'
											}]
								})
					}),
			createElements : function(service) {

				var serviceTargetCombox = new Ext.form.ComboBox({
							hiddenName : 'target',
							fieldLabel : '目标用户',
							blankText : '目标用户不能为空',
							store : this.serviceTargetStore,
							emptyText : '--请选择--',
							mode : 'local',
							anchor : '98%',
							triggerAction : 'all',
							valueField : 'varIndex',
							displayField : 'varName',
							loadingText : '加载中...',
							editable : false,
							selectOnFocus : true,
							forceSelection : true
						});
				var detailFormPanel = new Ext.form.FormPanel({
							border : false,
							frame : true,
							height : 220,
							items : [{
										layout : 'form',
										items : [{
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [{
																name : 'id',
																fieldLabel : 'id',
																xtype : 'hidden'
															}, {
																xtype : 'textfield',
																fieldLabel : '服务编码',
																name : 'code',
																width : 150,
																anchor : '98%',
																allowBlank : false,
																blankText : "服务编码不能为空！"
															}]
												}, {
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [{
																xtype : 'textfield',
																fieldLabel : '服务名称',
																name : 'name',
																width : 150,
																anchor : '98%'
															}]
												}, {
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [serviceTargetCombox]
												}, {
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [{
																xtype : 'checkbox',
																name : 'selectable',
																boxLabel : '是否为可选服务',
																width : 150,
																inputValue : 1,
																anchor : '98%'
															}]
												}]
									}]
						});
				return detailFormPanel;
			},

			init : function(initParams) {
				this.detailFormAjax = new Ext.data.Connection();
				this.detailFormAjax.on('beforerequest', function() {
							Ext.MessageBox.wait("保存数据中...", "提示");
						});

				this.detailFormAjax.on('requestcomplete', function() {
							Ext.MessageBox.hide();
						});

			},

			createWindow : function(app, service) {
				var hasData = service && service.id > 0;
				var winId = "service-detail-" + (hasData ? service.id : "0");
				var desktop = app.getDesktop();
				var module = this;
				var win = desktop.getWindow(winId);
				if (!win) {
					var detailFormPanel = this.createElements(service);
					var titleName = "新增服务-按ESC键退出";
					var tooltip = "新增服务";
					var actionName = "新增";
					var subUrl = "/companyPackage/addService.do";
					if (hasData) {
						this.serviceTargetStore.load({
									callback : function() {
										detailFormPanel.getForm().loadRecord(service);
									}
								});
						// 初始化JsModule
						// detailFormPanel.getForm().loadRecord(service);

						titleName = "编辑服务-按ESC键退出";
						tooltip = "编辑服务";
						actionName = "编辑";
						subUrl = "/companyPackage/modifyService.do";
					} else {
						this.serviceTargetStore.load();
					}

					win = desktop.createWindow({
								id : winId,
								title : titleName,
								iconCls : 'acc-icon',
								taskbuttonTooltip : tooltip,
								width : 480,
								shim : false,
								animCollapse : false,
								constrainHeader : true,
								maximizable : true,
								maximized : false,
								listeners : {
									'resize' : function(win, width, height) {
										var grid = win.items.get(0);
										var winMinWidth = 400;
										var winMinHeight = 240;
										if (width < winMinWidth || height < winMinHeight) {
											win.setWidth(winMinWidth);
											win.setHeight(winMinHeight);
											grid.setHeight(winMinHeight - 28);
										} else {
											grid.setHeight(height - 28);
										}
									}
								},
								items : detailFormPanel,
								buttons : [{
											text : actionName,
											handler : function() {
												var detailForm = detailFormPanel.getForm();
												if (!detailForm.isValid()) {
													Ext.Msg.alert("提示", "请按要求进行正确操作!");
													return;
												}
												var formValues = detailForm.getValues();

												module.detailFormAjax.request({
															url : Uec3.App.Constants.homeUrl + subUrl,
															success : function(res) {
																var result = Ext.decode(res.responseText);
																if (result && result.id > 0) {
																	detailForm.findField("id").setValue(result.id);
																	Ext.Msg.alert('提示', "操作成功!");
																} else {
																	Ext.Msg.alert("提示", "操作失败!");
																}

															},
															failure : function(res) {
																Ext.Msg.alert('失败', "网络出现异常,请重先连接");
															},
															params : formValues
														});
											}
										}, {
											text : '关闭',
											handler : function() {
												win.close();
											}
										}]
							});
				}
				win.show();
			}
		});